

$(function (){
    let information_exit = $('.information-exit');
    let information_val = $('.information-val');
    let information_hidden = $('.information-hidden');

    // 显示输入框
    information_exit.click(function (){
        let i = information_exit.index(this);
        $(information_val[2*i]).css('display', 'none');
        $(information_val[2*i+1]).css('display', 'none');
        // information_val.css('display', 'none');
        $(information_hidden[i]).css('display', 'flex');
    })

    // 取消按钮隐藏输入框
    $('.information-back').click(function (){
        information_hidden.css('display', 'none');
        information_val.css('display', 'inline-block');
    })

    // 发起修改信息的 ajax 请求
    $('.information-submit').click(function (){
        let i = $('.information-submit').index(this);
        let infor_in_dom = $('.information-input')[i];
        let key = infor_in_dom.name;
        let value = $(infor_in_dom).val();
        changeInformation(key, value);
    })
})

// ajax 请求函数
function changeInformation(key,value){
    let information_hidden = $('.information-hidden');
    let information_val = $('.information-val');
    $.ajax({
        async: false,
        type: "post",
        url: "/userIndex/changeInformation",
        dataType: "json",
        data: {key: key, value: value},
        success: function (data){
            console.log("请求成功！");
            information_hidden.css('display', 'none');
            information_val.css('display', 'inline-block');
            location.reload();  // 刷新页面
        },
        error: function (data){
            console.log("请求失败！");
        }
    })
}

// 左侧导航栏自动点击
$(function (){
    timer1 = setTimeout(function (){
        $($('.hidden-btn')[5]).click();
        $('.account-information').css('color', 'rgb(217, 32, 32)');
    })
})